package com.rocket.consumer;

import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "topicA",consumerGroup = "topicA-group")
public class TalkConsumerA implements RocketMQListener<String> {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;
    @Override
    public void onMessage(String hi) {
        //这里应该接到 你好的消息
        System.out.println("talkA接收到问候:"+hi);
        //回问
        String txt="你也好啊";
        Message<String> message = MessageBuilder.withPayload(txt).build();
        rocketMQTemplate.syncSend("topicB",message);
    }
}
